package com.example.floristshop;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;

import com.example.floristshop.adapters.CommentAdapter;
import com.example.floristshop.database.Comment;

import org.litepal.LitePal;

import java.util.Collections;
import java.util.List;

public class CommentListActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private RecyclerView recyclerView;

    private CommentAdapter adapter;
    private LinearLayoutManager manager;

    private List<Comment> commentList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_comments);

        // init data
        commentList = LitePal.where("flower_id==?", ""+getIntent().getLongExtra("flower_id", 1))
                .order("timestamp")
                .find(Comment.class);
        Collections.reverse(commentList);

        // get view
        toolbar = (Toolbar)findViewById(R.id.all_comments_toolbar);
        recyclerView = (RecyclerView)findViewById(R.id.all_comments_recyclerview);

        // set view
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        adapter = new CommentAdapter(this, R.layout.comment_item, commentList);
        manager = new LinearLayoutManager(this);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(manager);
    }
}